;#############################
;命令：
;nasm -f elf64 day3_1bss_1float.asm -o main.o && gcc main.o -o main -lc -no-pie && ./main
;输出：
;Value in arr[0] is 0.090000.
;Value in arr[1] is 0.190000.
;Value in arr[2] is 0.290000.
;Value in arr[3] is 0.390000.
;Value in arr[4] is 0.490000.
;Value in arr[5] is 0.590000.
;Value in arr[6] is 0.690000.
;Value in arr[7] is 0.790000.
;Value in arr[8] is 0.890000.
;Value in arr[9] is 0.990000.
;#############################
extern printf

section .data
	msg: db `Value in arr[%d] is %f.\n`, 0

section .bss
	arr: resd 10

section .text
	global main

main:
	push rbp
	mov rbp, rsp

;#################################################
	;赋值
	;没有指令将float立即数直接放入xmm0
	;将int数转为float数
	;通过除法计算获得想要的float数
	;除法计算是第六章的内容
	;eax寄存器作为初始值生成寄存器
	mov ecx, -1
	mov ebx, 0
	jmp compare_assign

execute_assign:
	add ecx, 10
	vcvtsi2ss xmm0, ecx
	mov edx, 100
	vcvtsi2ss xmm1, edx
	divss xmm0, xmm1
	movss dword [arr + 4 * ebx], xmm0
	inc ebx

compare_assign:
	cmp ebx, 10
	jl execute_assign
;#################################################

;#####################################################
	;打印
	mov ebx, 0
	jmp compare_print

execute_print:
	mov rdi, msg
	movsxd rsi, ebx
	vcvtss2sd xmm0, dword [arr + 4 * ebx]
	movq rdx, xmm0
	call printf

	inc ebx

compare_print:
	cmp ebx, 10
	jl execute_print
;#####################################################

	mov eax, 0
	leave
	ret
